package iodemo;

import io.Person;

import java.io.*;

/*
 * 对象流:经对象转换为字节数据存放在文件当中
 * */
public class OOSandOIS {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        String[] str = {"喝酒", "看小说"};
        Person p = new Person("张三", 15, "男", str);
        FileOutputStream fos = new FileOutputStream("./person1.obj", true);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(p);
        oos.close();
        System.out.println("写入成功");

        FileInputStream fis = new FileInputStream("./person1.obj");
        BufferedInputStream bis = new BufferedInputStream(fis);
        ObjectInputStream ois = new ObjectInputStream(bis);
        Person p1 = (Person) ois.readObject();
        System.out.println(p1.toString());
        ois.close();
    }
}
